<template>
  <view>
    
  </view>
</template>

<script>
  // #ifdef H5
  import wx from '@/utils/weixin-js-sdk/index.js'
  // #endif
  export default {
    data() {
      return {
        
      };
    },
    onShow() {
      const routes = getCurrentPages()
      const params = routes[routes.length - 1].options
      const longitude = decodeURIComponent(params.longitude)
      const latitude = decodeURIComponent(params.latitude)
      const name = decodeURIComponent(params.name)
      const address = decodeURIComponent(params.address)
      if(longitude && latitude){
        this.handleOpenMap(longitude, latitude,name,address)
      }else{
        uni.showToast({
          title:'缺少参数',
          icon:'none'
        })
      }
    },
    methods:{
      handleOpenMap(longitude, latitude,name,address){  // 打开地图
        // #ifdef H5
          wx.checkJsApi({
            jsApiList: ['openLocation'],
            success: (suc)=> {
              setTimeout(()=>{
                wx.openLocation({
                  latitude: parseFloat(latitude),
                  longitude: parseFloat(longitude),
                  name,
                  address,
                  scale: 18,
                  success(ret){
                    console.log(ret)
                  },
                  fail(err){
                    console.log(err)
                  }
                });
              },400)
            },
            fail:err=>{
              console.log('checkJsApi',err)
            }
          });
        // #endif
        /*#ifdef MP*/
          wx.openLocation({
            latitude: parseFloat(latitude),
            longitude: parseFloat(longitude),
            scale: 18,
            name,
            address,
            success(ret){
              console.log(ret)
            },
            fail(err){
              console.log(err)
            }
          });
        /*#endif*/
      },
    }
  }
</script>

<style lang="less">

</style>
